package com.elcl.support.versionupdate;

import android.app.Service;
import android.content.Intent;

import com.elcl.network.AppConstant;


/**
 * Created by lichunlin on 17/6/15.
 */

public class DownloadServiceCtrl implements VersionDownLoadListener {

    private Intent brodcastIntent = new Intent("com.marykay.versiondownload");

    Service service;
    public DownloadServiceCtrl(Service service) {
        this.service = service;
    }

    @Override
    public void fileAlreadyDownload() {
        brodcastIntent.putExtra(AppConstant.KEY_BROCASTER_TYPE,AppConstant.FILE_ALRADY_DOWNLOAD);
        service.sendBroadcast(brodcastIntent);
    }

    @Override
    public void downloadProgress(int progress) {
        brodcastIntent.putExtra(AppConstant.KEY_BROCASTER_TYPE, AppConstant.DOWNLOAD_PROGRESS);
        brodcastIntent.putExtra("progress",progress);
        service.sendBroadcast(brodcastIntent);
    }

    @Override
    public void downloadSuccess(byte downLoadType) {
        brodcastIntent.putExtra(AppConstant.KEY_BROCASTER_TYPE, AppConstant.DOWNLOAD_SUCCESS);
        brodcastIntent.putExtra(AppConstant.KEY_BROCASTER_SUCCESS_TYPE, downLoadType);
        service.sendBroadcast(brodcastIntent);
    }

    @Override
    public void isWifiAvailable(boolean isAvailable) {
        brodcastIntent.putExtra(AppConstant.KEY_BROCASTER_TYPE, isAvailable);
        service.sendBroadcast(brodcastIntent);
    }

    @Override
    public void downloadFailed() {
        brodcastIntent.putExtra(AppConstant.KEY_BROCASTER_TYPE, AppConstant.DOWNLOAD_FAILED);
        service.sendBroadcast(brodcastIntent);

    }

}
